/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testencryption;

import java.util.StringTokenizer;

/**
 *
 * @author Victor Alvarez
 */
public class Reverser extends Transpose {

    public Reverser(String s) {
        // Complete the constructor
        super(s); 
    }

    public String reverseText(String word) {
//     Complete this method so that it reverses the original string
         StringTokenizer wordToEncrypt = new StringTokenizer(word);
         StringBuffer encode = new StringBuffer();
         String s = " ";
         
         while(wordToEncrypt.hasMoreTokens())
         {
             s = wordToEncrypt.nextToken();
            
            encode.insert(0, " " + s); // inserts word at 0 place 
            
         }

      return encode.toString();
    }

    public String decode(String word) {
    // Complete this method so that it reverses the reversed string
         StringTokenizer wordToDecrypt = new StringTokenizer(word);
         StringBuffer decode = new StringBuffer();
         String s = " ";
         
         while(wordToDecrypt.hasMoreTokens())
         {
            s = wordToDecrypt.nextToken();
            s = encode(s) + " ";

            decode.insert(0, s ); // inserts word at 0 place              
         }
 
      return decode.toString();
    }
}
